<!--
 * @Description: 权限校验组件
 * @Autor: Zhu_liangyu
 * @Date: 2020-07-16 11:03:30
--> 
<template></template>
<script>
import { judgeAuthorityArray } from "@/api/org/manager";
export default {
  name: "authority-tool",
  props: {
    //权限key值
    authorityKeys: {
      type: Array,
      required: true
    },
    //权限数据(后面会根据权限数据返回true/false)
    hasAuthority: {
      type: Object,
      default: null
    }
  },
  data() {
    return {
      authorityArr: [] //权限数据 boolean 下标对应authorityKeys
    };
  },
  created() {
    this.judgeAuthority();
  },
  methods: {
    judgeAuthority() {
      judgeAuthorityArray(this.authorityKeys).then(response => {
        this.authorityArr = response.data.data;
      });
    }
  },
  watch: {
    authorityArr(arr) {
      var i = 0;
      for (var d in this.hasAuthority) {
        this.hasAuthority[d] = arr[i];
        i++;
      }
      this.$emit("authorityArr", arr);
    }
  }
};
</script>